<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRegist extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => 'required|max:20|unique:users,name',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|max:20|confirmed'
        ];
    }

    public function messages()
    {
        return [
            'username.required' => '登陆账号必填',
            'username.max' => '登陆账号不能超过20位字符',
            'username.unique' => '用户名已存在，请重新输入',
            'email.required' => '邮箱必填',
            'email.unique' => '邮箱已注册，请重新输入',
            'email.email' => '邮箱格式错误',
            'password.required' => '密码必填',
            'password.max' => '密码最多不能超过20位字符',
            'password.confirmed' => '重复密码不正确'
        ];
    }
}
